// JavaScript Document

function validate1()
{
	
    if(document.questionnaire2.district[document.questionnaire2.district.selectedIndex].value==0)
	{
	  alert("Please Select District Name");
	  document.questionnaire2.district.focus();
	   return false;
	}	
	if(document.questionnaire2.block[document.questionnaire2.block.selectedIndex].value==0)
	{
	  alert("Please Select Block Name");
	  document.questionnaire2.block.focus();
	   return false;
	}
	if(document.questionnaire2.tehsil[document.questionnaire2.tehsil.selectedIndex].value==0)
	{
	  alert("Please Select Tehsil Name");
	  document.questionnaire2.tehsil.focus();
	   return false;
	}
	if(document.getElementById('scheme_name').value=="")
	{
		alert('Please Enter Name of the Schemes');
		document.getElementById('scheme_name').focus();
		return false;
	}
	/*if(document.getElementById('capital_cost').value=="")
	{
		alert('Please Enter Capital Cost');
		document.getElementById('capital_cost').focus();
		return false;
	}
	if(document.getElementById('capital_cost').value.length>5)
	{
		alert('Capital Cost Should be Max 5 Character');
		document.getElementById('capital_cost').focus();
		return false;
		
	}*/
	
	if(document.getElementById('scheme_sactioned')[document.getElementById('scheme_sactioned').selectedIndex].value==0)
		{
			alert('Please Select Type of Scheme Sanctioned');
			document.getElementById('scheme_sactioned').focus();
			return false;
		}
		
	if(document.getElementById('scheme_sactioned')[document.getElementById('scheme_sactioned').selectedIndex].value=='Other' && document.getElementById('scheme_sactioned_other').value=="")
		{
			alert('Please Enter Scheme Sanctioned of Other Field');
			document.getElementById('scheme_sactioned_other').focus();
			return false;
		}
	
	 /*var chks = document.getElementsByName('scheme_sactioned'+'[]');
     var hasChecked = false;
     for (var i = 0; i < chks.length; i++)
     {
     	if (chks[i].checked)
     	{
     		hasChecked = true;
     		break;
     	}
     }
	 if (hasChecked == false)
    {
    	alert("Please Select at Least One Scheme Sanctioned");
    	return false;
    }
	var chks = document.getElementsByName('scheme_sactioned'+'[]');
     var hasChecked = false;
     for (var i = 1; i < chks.length; i++)
     {
     	if (chks[i].checked)
     	{
	 
	 		if(chks[i].value=="" && document.getElementById('scheme_sactioned_other').value=="")
	 		{
	    		alert("Please Enter Scheme Sanctioned Under Other Field");
				document.getElementById('scheme_sactioned_other').focus();
				return false;
	 		}
	 	}
	 }*/
	 //if(document.ElementById('other_specify').value=="")
	 //{
		//alert("Please enter otherspecify");
		//document.ElementById('other_specify').focus();
		//return false;
	 //}
	
	 //}
	 //hasChecked = true;
     //break;
     //}
	 //}
	
	
	
	if(document.questionnaire2.panchayat[document.questionnaire2.panchayat.selectedIndex].value==0)
	{
	  alert("Please Select Grampanchayat Name");
	  document.questionnaire2.panchayat.focus();
	   return false;
	}
	if(document.questionnaire2.village[document.questionnaire2.village.selectedIndex].value==0)
	{
	  alert("Please Select Village Covered Name");
	  document.questionnaire2.village.focus();
	   return false;
	}
	var counthabit=document.getElementById('habit_count').value
	for(var i=1;i<=counthabit;i++)
	{
		if(document.getElementById('hp_no'+i).value=="")
		{
			alert('Please Enter No. of HP'+i);
			document.getElementById('hp_no'+i).focus();
			return false;
		}
		/*if(document.getElementById('sp_no'+i).value=="")
		{
			alert('Please Enter No. of Single Phase'+i);
			document.getElementById('sp_no'+i).focus();
			return false;
		}*/
	}
	/*if(document.getElementById('population_benefited1').value=="")
	{
		alert('Please Enter Population Benefited Field! If You Have No Data Fill 0');
		document.getElementById('population_benefited1').focus();
		return false;
	}*/
	var a=document.getElementById('population_benefited1').value;
	var b=document.getElementById('present_population').value;
	var c=document.getElementById('factor1').value;
	alert('Value of Population Benefited Field is '+ a +' , Present Population is '+ b +' and Population Factor is ' + c);
    	/*if(r==false)
		{
		
			document.getElementById('population_benefited1').focus();
			return false;
		}*/
	
	/*if(document.getElementById('present_population').value=="")
	{
		alert('Please Enter Present Population Field');
		document.getElementById('present_population').focus();
		return false;
	}*/
	if(document.getElementById('DP_population').value=="")
	{
		alert('Please Enter Design Parameter Population Field! If You Have No Data Fill 0');
		document.getElementById('DP_population').focus();
		return false;
	}
	/*if(document.getElementById('DP_water_demand').value=="")
	{
		alert('Please Enter Water Demand Field');
		document.getElementById('DP_water_demand').focus();
		return false;
	}*/
	
}

function enable_text50(status)
{
  status=!status;
  document.getElementById('scheme_sactioned_other').disabled=status;
    
}

function enable_sanc12(status)
{
  
	if(document.getElementById('scheme_sactioned')[document.getElementById('scheme_sactioned').selectedIndex].value=='Other')
	{
  		status=!status;
  		document.getElementById('scheme_sactioned_other').disabled=status;
  		document.getElementById('scheme_sactioned_other').focus();
	}
	else
	{
		document.getElementById('scheme_sactioned_other').disabled=true;	
	}

}


function alphabet(field)
{
    var valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
    var ok = "yes";
    var temp;
    for (var i=0; i<field.value.length; i++)
	{
    temp = "" + field.value.substring(i, i+1);
    if (valid.indexOf(temp) == "-1") ok = "no";
    }
    if (ok == "no")
    {
       alert("Invalid entry! Only Alphabetic Characters are Accepted!");
        field.focus();
        //field.select();
        return false;
   }

}


function numeric(field)
{
    var valid = "0123456789"
    var ok = "yes";
    var temp;
    for (var i=0; i<field.value.length; i++)
	{
   temp = "" + field.value.substring(i, i+1);
   if (valid.indexOf(temp) == "-1") ok = "no";
   }
   if (ok == "no")
   {
       alert("Invalid entry! Only Numeric Characters are Accepted!");
       //field.focus();
       field.select();
       return false;
   }

}

function float(field)
{
	
	var val = field.value;
	if(isNaN(val))
	{
		alert("Invalid entry! Only Integer and Float Values are Accepted!");
		field.focus();
		return false;
	}
}


/*function float(field)
{
	//var DigitsAfterDecimal = 2;
	var val = field.value;
	if(isNaN(val))
	{
		alert("Please enter valid decimal value");
		field.focus();
		return false;
	}
	if(val.indexOf(".") > -1)
	{
		if(val.length - (val.indexOf(".")+1) > DigitsAfterDecimal)
		{
			alert("Please enter valid decimal value. Only digits are allowed after decimal.");         								   			field.select();
			return false; 
		}
	}
}*/


/*function setReadOnly(valobj)
{
		//document.getElementById('household'+obj).style.backgroundcolor="#eeeeee";
		//document.getElementById('population_sc1').readonly=1;
		//document.getElementById('population_sc1').value="Not Applicable";
		document.getElementById('OA_operational_status').disabled=true;
		//document.getElementById('frequency_supply').disabled=true;
		//document.getElementById('duration_of_supply').disabled=true;
		//document.getElementById('type_of_disinfection').disabled=true;
		//document.getElementById('disinfection_frequecy').disabled=true;
		//document.getElementById('Quantity_of_chemical').disabled=true;
		document.getElementById('OA_operational_status').value="defunct";
   
}
function setEnable(valobj)
{

		//document.getElementById('population_sc1').style.backgroundcolor="#ffffff";
		//document.getElementById('population_sc1').readonly=0;
		//document.getElementById('population_sc1').value="";
		document.getElementById('OA_operational_status').disabled=false;
		//document.getElementById('frequency_supply').disabled=false;
		//document.getElementById('duration_of_supply').disabled=false;
		//document.getElementById('type_of_disinfection').disabled=false;
		//document.getElementById('disinfection_frequecy').disabled=false;
		//document.getElementById('Quantity_of_chemical').disabled=false;
		document.getElementById('OA_operational_status').value="operation";
	
}*/



function validate2()
{
	var countloc=document.getElementById('loccount').value;
	//alert(countloc);
	for(var p=1; p<countloc; p++)
	{
		if(document.getElementById('location'+p).value=="")
		{
	   		alert('Please Enter Location Field'+p);
	   		document.getElementById('location'+p).focus();
	   		return false;
		}
	
		var chks = document.getElementsByName('function_status'+p);
     	var hasChecked = false;
     //if(!chk.checked)
	 //{
	 	for (var i = 0; i < chks.length; i++)
     	{
     		if (chks[i].checked)
     		{
     			hasChecked = true;
     			break;
     		}
     	}
	 	if (hasChecked == false)
    	{
    		alert('Please Check at Least One in Functional Status'+p);
    		return false;
    	}
	
	
	
		var rad=document.getElementById('function_status'+p);
	 	//var rad1=document.getElementById('remarks'+p);
	 	//alert(rad.value);
	 	var chks = document.getElementsByName('repairable_status'+p);
     	var hasChecked = false;
     	if(!rad.checked)
	 	{
	 		for (var i = 0; i < chks.length; i++)
     		{
     			if (chks[i].checked)
     			{
     				hasChecked = true;
    				 break;
     			}
     		}
	 		if (hasChecked == false)
    		{
    			alert('Please Check at Least One in Repairable Status'+p);
    			return false;
    		}
		}
		else
		{
	/*if(!rad.checked && rad1.value=="")
	{
	   alert('Please Enter the Fields Remarks'+p);
	   rad1.focus();
	   return false;
	}*/
	
	
	
	//var rad=document.getElementById('function_status'+p);
	 
	 //alert(rad.value);
	 var chks = document.getElementsByName('opration_status'+p);
     var hasChecked = false;
     //if(!chk.checked)
	 //{
	 for (var i = 0; i < chks.length; i++)
     {
     	if (chks[i].checked)
     	{
     		hasChecked = true;
     		break;
     	}
     }
	 if (hasChecked == false)
    {
    	alert('Please Check at Least One in Operational Status'+p);
    	return false;
    }
	//}
	
	var chks = document.getElementsByName('quality_status'+p);
    var hasChecked = false;
	for (var i = 0; i < chks.length; i++)
     {
     	if (chks[i].checked)
     	{
     		hasChecked = true;
     		break;
     	}
     }
	 if (hasChecked == false)
    {
    	alert('Please Check at Least One in Quality Status'+p);
    	return false;
    }
	
	var chks = document.getElementsByName('yield'+p);
    var hasChecked = false;
	for (var i = 0; i < chks.length; i++)
     {
     	if (chks[i].checked)
     	{
     		hasChecked = true;
     		break;
     	}
     }
	 if (hasChecked == false)
    {
    	alert('Please Check at Least One in Yield'+p);
    	return false;
    }
	
	var chks = document.getElementsByName('seasonal_flunctuation'+p);
    var hasChecked = false;
	for (var i = 0; i < chks.length; i++)
     {
     	if (chks[i].checked)
     	{
     		hasChecked = true;
     		break;
     	}
     }
	 if (hasChecked == false)
    {
    	alert('Please Check at Least One in Seasonal Fluctuation'+p);
    	return false;
    }
	
	
	if(document.getElementById('water_table_fluctuation_min'+p).value=="")
	{
	   alert('Please Enter Water Table Flunctuation in min Field');
	   document.getElementById('water_table_fluctuation_min'+p).focus();
	   return false;
	}
	if(document.getElementById('water_table_fluctuation_max'+p).value=="")
	{
	   alert('Please Enter Water Table Flunctuation in Max Field');
	   document.getElementById('water_table_fluctuation_max'+p).focus();
	   return false;
	}
	}
	
	
}
}

function validate3()
{
    	
	var chks = document.getElementsByName('OA_current_status');
     var hasChecked = false;
     //if(!chk.checked)
	 //{
	 for (var i = 0; i < chks.length; i++)
     {
     	if (chks[i].checked)
     	{
     		hasChecked = true;
     		break;
     	}
     }
	 if (hasChecked == false)
    {
    	alert('Please Check at Least One in Current Status of Schemes');
    	return false;
    }
	var chks = document.getElementsByName('OA_operational_status');
     var hasChecked = false;
     for (var i = 0; i < chks.length; i++)
     {
     	if (chks[i].checked)
     	{
	 		//alert(chks[i].value);
	 		hasChecked = true;
     		break;
     	}
	 }
	 
	 if (hasChecked == false)
    {
    	alert("Please Select at Least One Operational Status");
    	return false;
    }
	 var chks = document.getElementsByName('OA_operational_status');
     var hasChecked = false;
     for (var i = 1; i < chks.length; i++)
     {
     	if (chks[i].checked)
     	{
	 		//alert(chks[i].value);
	 		if(chks[i].value=="Other" && document.getElementById('OA_operational_other').value=="")
	 		{
	    		alert("Please Enter Operational Status in Other Specify Field");
				document.getElementById('OA_operational_other').focus();
				return false;
	 		}
			
			
	 	}
	 }
	 
	 
	
	
	/*if(document.getElementById('manpower_cost_09_10').value=="")
	{
	   alert('Please Enter Manpower Cost of 2009-10 Field');
	   document.getElementById('manpower_cost_09_10').focus();
	   return false;
	}
	
	if(document.getElementById('manpower_cost_08_09').value=="")
	{
	   alert('Please Enter Manpower Cost of 2008-09 Field');
	   document.getElementById('manpower_cost_08_09').focus();
	   return false;
	}
	if(document.getElementById('manpower_cost_07_08').value=="")
	{
	   alert('Please Enter Manpower Cost of 2007-08 Field');
	   document.getElementById('manpower_cost_07_08').focus();
	   return false;
	}
	if(document.getElementById('material_cost_09_10').value=="")
	{
	   alert('Please Enter Material Cost of 2009-10 Field');
	   document.getElementById('material_cost_09_10').focus();
	   return false;
	}
	
	if(document.getElementById('material_cost_08_09').value=="")
	{
	   alert('Please Enter Material Cost of 2008-09 Field');
	   document.getElementById('material_cost_08_09').focus();
	   return false;
	}
	if(document.getElementById('material_cost_07_08').value=="")
	{
	   alert('Please Enter Material Cost of 2007-08 Field');
	   document.getElementById('material_cost_07_08').focus();
	   return false;
	}*/
	
	var chks = document.getElementsByName('maintenence_machanism');
     var hasChecked = false;
     for (var i = 0; i < chks.length; i++)
     {
     	if (chks[i].checked)
     	{
	 		//alert(chks[i].value);
	 		hasChecked = true;
     		break;
     	}
	 }
	 
	 if (hasChecked == false)
    {
    	alert("Please Select at Least One Preventive Maintenance Mechanisms in Place");
    	return false;
    }
	
	var chks = document.getElementsByName('exist_report_sys'+'[]');
    	var hasChecked = false;
     for (var i = 0; i < chks.length; i++)
     {
     	if (chks[i].checked)
     	{
	 		//alert(chks[i].value);
	 		hasChecked = true;
     		break;
     	}
	 }
	 
	 if (hasChecked == false)
    {
    	alert("Please Select at Least One Existing Reporting System");
    	return false;
    }
	
	var chks = document.getElementsByName('exist_report_sys'+'[]');
     var hasChecked = false;
     for (var i = 1; i < chks.length; i++)
     {
     	if (chks[i].checked)
     	{
	 		//alert(chks[i].value);
	 		if(chks[i].value=="Other" && document.getElementById('report_other').value=="")
	 		{
	    		alert("Please Enter Existing Reporting System in Other Field");
				document.getElementById('report_other').focus();
				return false;
	 		}
	 	}
	 }
	
	/*if(document.getElementById('exist_report_sys'+'[]').value=="Other" && document.getElementById('report_other').value=="")
		{
			alert('Please Enter Existing Reporting System in Other Field');
			document.getElementById('report_other').focus();
			return false;
		}*/
	/*if(document.getElementById('exist_report_sys')[document.getElementById('exist_report_sys').selectedIndex].value==0)
		{
			alert('Please Select Existing Reporting System');
			document.getElementById('exist_report_sys').focus();
			return false;
		}
		
	if(document.getElementById('exist_report_sys')[document.getElementById('exist_report_sys').selectedIndex].value=='Other' && document.getElementById('report_other').value=="")
		{
			alert('Please Enter Existing Reporting System in Other Field');
			document.getElementById('report_other').focus();
			return false;
		}*/	
	if(document.getElementById('time_taken')[document.getElementById('time_taken').selectedIndex].value==0)
		{
			alert('Please Select Time Taken to Address the Complaint');
			document.getElementById('time_taken').focus();
			return false;
		}
	
	
	
	
	/*if(document.getElementById('time_taken').value=="")
	{
	   alert('Please Enter Time Taken to Address the Complaint Field');
	   document.getElementById('time_taken').focus();
	   return false;
	}*/
	var chks = document.getElementsByName('institutional'+'[]');
    var hasChecked = false;
     for (var i = 0; i < chks.length; i++)
     {
     	if (chks[i].checked)
     	{
	 		//alert(chks[i].value);
	 		hasChecked = true;
     		break;
     	}
	 }
	 
	 if (hasChecked == false)
    {
    	alert("Please Select at Least One PHED Institutional");
    	return false;
    }
	 var chks = document.getElementsByName('institutional'+'[]');
     var hasChecked = false;
     for (var i = 1; i < chks.length; i++)
     {
     	if (chks[i].checked)
     	{
	 		//alert(chks[i].value);
	 		if(chks[i].value=="" && document.getElementById('institutional_other').value=="")
	 		{
	    		alert("Please Enter PHED  Institutional Other Field");
				document.getElementById('institutional_other').focus();
				return false;
	 		}
	 	}
	 }
	var chks = document.getElementsByName('financial'+'[]');
    var hasChecked = false;
     for (var i = 0; i < chks.length; i++)
     {
     	if (chks[i].checked)
     	{
	 		//alert(chks[i].value);
	 		hasChecked = true;
    		 break;
     	}
	 }
	 
	 if (hasChecked == false)
    {
    	alert("Please Select at Least One PHED Financial");
    	return false;
    }
	 var chks = document.getElementsByName('financial'+'[]');
     var hasChecked = false;
     for (var i = 1; i < chks.length; i++)
     {
     	if (chks[i].checked)
     	{
	 		//alert(chks[i].value);
	 		if(chks[i].value=="" && document.getElementById('financial_other').value=="")
	 		{
	    		alert("Please Enter PHED  Financial Other Field");
				document.getElementById('financial_other').focus();
				return false;
	 		}
	 	}
	 }
	var chks = document.getElementsByName('operational'+'[]');
    var hasChecked = false;
     for (var i = 0; i < chks.length; i++)
     {
     	if (chks[i].checked)
     	{
	 		//alert(chks[i].value);
	 		hasChecked = true;
    		 break;
    	}
	 }
	 
	 if (hasChecked == false)
    {
    	alert("Please Select at Least One PHED Operational");
    	return false;
    }
	 var chks = document.getElementsByName('operational'+'[]');
     var hasChecked = false;
     for (var i = 1; i < chks.length; i++)
     {
     	if (chks[i].checked)
     	{
		 	//alert(chks[i].value);
	 		if(chks[i].value=="" && document.getElementById('operational_other').value=="")
	 		{
	    		alert("Please Enter PHED  Operational Other Field");
				document.getElementById('operational_other').focus();
				return false;
	 		}
	 	}
	 }
}
/*function enable_text3(status)
{
  status=!status;
  document.q2_main.OA_operational_other.disabled=status;
  document.q2_main.PHED_institutional_other.disabled=status;
  document.q2_main.PHED_financial_other.disabled=status;
  document.q2_main.PHED_operational_other.disabled=status;
}*/

function exist(field)
{
	if(field.value<1 || field.value>12)
    {
		alert('Please Enter Value 1 to 12 No.');
		//document.getElementById('months_water_retained_bawaries').select();
		field.select();
		return false;
	}
}
	


function enable_text31(status)
{
  status=!status;
  document.q2_main.OA_operational_other.disabled=status;
  document.getElementById('OA_operational_other').focus();
  return false;
}
function enable_text39(status)
{
	if(document.getElementById('exist_report_sys')[document.getElementById('exist_report_sys').selectedIndex].value=='Other')
	{
  		status=!status;
  		document.getElementById('report_other').disabled=status;
  		document.getElementById('report_other').focus();
	}
	else
	{
		document.getElementById('report_other').disabled=true;
	}
}


function enable_text32(status)
{
  status=!status;
  document.q2_main.institutional_other.disabled=status;
  document.getElementById('institutional_other').focus();
  return false;
}
function enable_text33(status)
{
  status=!status;
  document.q2_main.financial_other.disabled=status;
  document.getElementById('financial_other').focus();
  return false;
}
function enable_text34(status)
{
  status=!status;
  document.q2_main.operational_other.disabled=status;
  document.getElementById('operational_other').focus();
  return false;
}
function enable_text35(status)
{
  status=!status;
  document.q2_main.OA_operational_other.disabled=status;
  document.q2_main.OA_operational_other.value="";
}
/*function enable_text36(status)
{
  status=!status;
  document.q2_main.PHED_institutional_other.disabled=status;
}
function enable_text37(status)
{
  status=!status;
  document.q2_main.PHED_financial_other.disabled=status;
}
function enable_text38(status)
{
  status=!status;
  document.q2_main.PHED_operational_other.disabled=status;
}*/

function enable_exist(status)
{
	
  		status=!status;
  		document.getElementById('report_other').disabled=status;
  		document.getElementById('report_other').focus();
		document.getElementById('exist_report_sys'+'[]').value="Other";
		
	
}


function validate4()
{
	var counthab=document.getElementById('habcount').value;
	for(var i=1;i<counthab;i++)
	{
		var chks = document.getElementsByName('critical'+i);
    	//alert(chks);
		var hasChecked = false;
     	for (var j = 0; j < chks.length; j++)
     	{
     		if (chks[j].checked)
     		{
	 			//alert(chks[i].value);
	 			hasChecked = true;
     			break;
     		}
	 	}
	 
	 	if (hasChecked == false)
    	{
    		alert("Please Select at Least One Critical"+i);
    		return false;
    	}
		var rad = document.getElementById('critical'+i);
		//alert(rad.value);
		
			if(rad.checked)
			{
				var chk = document.getElementsByName('CH_quality'+i+'[]');
    			var hasChecked = false;
     			for (var j = 0; j < chk.length; j++)
     			{
     				if (chk[j].checked)
     				{
	 					//alert(chks[i].value);
	 					hasChecked = true;
     					break;
     				}
	 			}
	 
	 			if (hasChecked == false)
    			{
    				alert("Please Select at Least One Critical Village in Terms of Quality"+i);
    				return false;
    			}
				var chk = document.getElementsByName('CH_quantity'+i+'[]');
    			var hasChecked = false;
     			for (var j = 0; j < chk.length; j++)
     			{
     				if (chk[j].checked)
     				{
	 					//alert(chks[i].value);
	 					hasChecked = true;
     					break;
     				}
	 			}
	 
	 			if (hasChecked == false)
    			{
    				alert("Please Select at Least One Critical Village in Terms of Quantity"+i);
    				return false;
    			}
			
		}
		
		
	}
	
	/*var counthab=document.getElementById('habcount').value
	for(var i=1;i<counthab;i++)
	{
		if(document.getElementById('water_supply_no'+i).value=="")
		{
			alert('Please Enter Water Supply No.'+i);
			document.getElementById('water_supply_no'+i).focus();
			return false;
		}
		if(document.getElementById('water_supply_qty'+i).value=="")
		{
			alert('Please Enter Water Supply Quantity'+i);
			document.getElementById('water_supply_qty'+i).focus();
			return false;
		}
		if(document.getElementById('water_supply_area'+i).value=="")
		{
			alert('Please Enter Water Supply Area Covered'+i);
			document.getElementById('water_supply_area'+i).focus();
			return false;
		}
	}*/	
}